package com.lots.controller.user;

import com.lots.domain.dto.DishUploadDto;
import com.lots.domain.entity.Dish;
import com.lots.domain.entity.DishCategory;
import com.lots.domain.entity.DishDetail;
import com.lots.utils.Result;
import com.lots.service.DishDetailService;
import com.lots.service.DishService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/dish")
@Tag(name = "菜品管理相关接口")
public class DishController {
    @Autowired
    private DishService dishService;
    @Autowired
    private DishDetailService dishDetailService;


    /**
     * 查询全部菜品
     */
    @GetMapping()
    @Operation(summary = "查询菜品")
    public Result getDish(){
        List<Dish> dishList = dishService.getDishList();
        return Result.success(dishList);
    }
    /**
     * 根据id查询菜品详情
     */
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询菜品详情")
    public Result getDishById(@PathVariable Long id){
        DishDetail dishDetail = dishDetailService.getDishById(id);
        return Result.success(dishDetail);
    }
    /**
     * 判断用户是否点赞
     */
    @GetMapping("/isLiked/{id}")
    @Operation(summary = "判断用户是否点赞")
    public Result getIsLiked(@PathVariable Long id){
        return Result.success(dishDetailService.getIsLiked(id));
    }

    /**
     * 菜品中心查询菜品类别
     */
    @GetMapping("/categories")
    @Operation(summary = "查询菜品类别")
    public Result getDishCategories(){
        List<DishCategory> categories = dishService.getDishCategories();
        return Result.success(categories);
    }

    /**
     * 根据类别id查询菜品
     */
    @GetMapping("/category/{id}")
    @Operation(summary = "根据类别id查询菜品")
    public Result getDishByCategoryId(@PathVariable Integer id){
        List<Dish> dishList = dishService.getDishByCategoryId(id);
        return Result.success(dishList);
    }


    /**
     * 首页根据类别id查询10个
     */
    @GetMapping("/category/main/{id}")
    @Operation(summary = "根据类别id查询菜品")
    public Result getDishByCategoryIdTop(@PathVariable Integer id){
        List<Dish> dishList = dishService.getDishByCategoryIdTop(id);
        return Result.success(dishList);
    }


    /**
     * 热门菜品绑单
     */
    @GetMapping("/hot")
    @Operation(summary = "热门菜品绑单")
    public Result getHotDish(){
        List<Dish> dishList = dishService.getTop();
        return Result.success(dishList);
    }
    /**
     *新品榜单
     */
    @GetMapping("/new")
    @Operation(summary = "新品榜单")
    public Result getNewDish(){

        List<Dish> dishList = dishService.getMathTop();
        return Result.success(dishList);
    }

    /**
     * 上传作品
     */
    @PostMapping("/upload")
    @Operation(summary = "上传作品")
    public Result upload(@RequestBody DishUploadDto dishUploadDto){
        log.info("上传作品{}",dishUploadDto);
        dishService.upload(dishUploadDto);
      return Result.success("上传成功！");
    }


}
